import 'package:flutter/material.dart';
import 'package:ichinesereader/controller/schooladmin.dart';
import 'package:get/get.dart';
import 'package:ichinesereader/models/class/ClassDetails.dart';
import 'package:ichinesereader/themes/appTheme.dart';
import 'package:ichinesereader/utils/log.dart';

class ClassSelectionDropDownForSchoolAdmin extends StatelessWidget {
  ClassSelectionDropDownForSchoolAdmin({
    Key? key,
  }) : super(key: key);
  final SchoolAdminController _schoolcontroller = Get.find();

  @override
  Widget build(BuildContext context) {
    Log.debug('build class selection dropdown for school admin');

    return Obx((() {
      if (_schoolcontroller.currentSchoolAdminClass.classId != null) {
        return Container(
          width: 220,
          height: 42,
          child: DropdownButtonFormField(
            dropdownColor: Get.isDarkMode
                ? AppTheme.colors.darkTheme2
                : Get.theme.primaryColorDark,
            icon: Icon(
              Icons.arrow_drop_down_outlined,
              color: Get.isDarkMode? Get.theme.primaryColorDark:Colors.black,
            ),
            hint: Text('Choose Class'.tr, style:TextStyle(color: Get.isDarkMode? Get.theme.primaryColorDark: Colors.black),),
            value: _schoolcontroller.getCurrentClass(),
            items: _schoolcontroller.classItems.map((selectedClass) {
              return DropdownMenuItem(
                value: selectedClass,
                child: Text(
                  selectedClass.className.toString(),
                  style: TextStyle(
                      fontSize: 14.0,
                      color: Get.isDarkMode
                          ? Get.theme.primaryColorDark
                          : Get.theme.primaryColorLight),
                  overflow: TextOverflow.fade,
                ),
              );
            }).toList(),
            onChanged: (value) {
              _schoolcontroller.studentItems.clear();
              _schoolcontroller
                  .setSchoolAdminCurrentClass(value as ClassDetails);
              var tc = value;
              if (tc.classId == 'All')
                _schoolcontroller.fetchSchoolAllStudents(0, 250);
              else
                _schoolcontroller.fetchSchoolStudentsByClassId(
                    tc.classId.toString(), false);
            },
          ),
        );
      } else {
        return Text('');
      }
    }));
  }
}
